#include "File.h"
#include <cstdlib>
bool File::OpenRead(const std::string& filename)
{
	m_file.open(filename.c_str());
	return m_file.good();
}

void File::Close()
{
	m_file.close();
}
bool File::GetString(std::string* string)
{
	const int MAX_BUF = 2000;
	char buffer[MAX_BUF];
	do
	{
        m_file.getline(buffer,MAX_BUF);
        if(!m_file.good() || m_file.eof())
	    {
		    return false;
	    }
    }while(buffer[0] == '#' || buffer[0] == '\0');

	*string = buffer;
	return true;
}

bool File::GetInteger(int* result)
{
	std::string s;
	if(!GetString(&s))
	{
		return false;
	}
	*result = atoi(s.c_str());
	return true;
}

bool File::GetFloat(float* result)
{
	std::string s;
	if(!GetString(&s))
	{
		return false;
	}
	*result = (float)atof(s.c_str());
	return true;
}
